package com.suixun.enums;

/**
 * APICodes.java
 *
 *  API相关的枚举内容
 *
 * @author <a href="mailto:huangy@17find.com">hellmash</a>
 * @version create on 2015-07-20 10:43
 *          <p>
 *          CopyRight(c)2015 杭州随寻科技有限公司 17find.com 版权所有
 */
public enum APICode {

    //HTTP常规code
    HTTP_200(200, "服务器已成功返回您请求的数据"),
    HTTP_201(201, "您新建或修改的数据已成功"),
    HTTP_202(202, "您的请求已经进入后台排队，请稍候"),
    HTTP_204(204, "删除数据成功"),
    HTTP_400(400, "错误的请求"),
    HTTP_401(401, "登录已过期，为保护您的账号安全，请重新登录！"),
    HTTP_403(403, "您不能访问这项资源"),
    HTTP_404(404, "您访问的资源不存在"),
    HTTP_406(406, "您的请求不被允许"),
    HTTP_410(410, "您请求的数据已经被永久删除"),
    HTTP_422(422, "您创建资源失败,请登录后操作"),
    HTTP_500(500, "服务器发生错误,请稍后再操作"),
    
    API_10001(10001, "该用户不存在或密码错误,请确认后重新登录"),
    API_10008(10008, "登录成功"),
    
    HTTP_0(0, "操作成功"),
    /**自定义内容**/
    HTTP_900(900, ""),
    SUCCESS(0, "操作成功"),
    FAIL(-1, "操作失败"),
    CUSTOMER(900, "")
;

    private int code;

    private String msg;

    private APICode(int _code, String _msg){
        this.code   = _code;
        this.msg    = _msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getNameById(int code) {
        for (APICode g : APICode.values()) {
            if (g.getCode() == code) {
                return g.getMsg();
            }
        }
        return "";
    }
    
    public APICode setCustomMsg(String msg) {
        this.msg = msg;
        return this;
    }
}
